"""
随机数生成函数
"""

import uuid
import logging
logger = logging.getLogger(__name__)


def uuid_prefix(prefix: str = None) -> str:
    """生成随机UUID"""
    uuid_str = str(uuid.uuid4())
    if prefix:
        uuid_str = f"{prefix}-{uuid_str}"

    return uuid_str


def uuid_hex() -> str:
    """返回不含连字符的32位UUID"""
    return uuid.uuid4().hex


def uuid_upper(prefix: str = None) -> str:
    """返回不含连字符且全大写字符的32位UUID"""
    uuid_str = uuid.uuid4().hex.upper()
    if prefix:
        uuid_str = f"{prefix}-{uuid_str}"

    return uuid_str


def uuid3_str(namespace=uuid.NAMESPACE_DNS, name: str = 'zxwq') -> str:
    """基于名称空间和名称生成UUID 确定性"""
    return str(uuid.uuid3(namespace, name))


def uuid5_str(namespace=uuid.NAMESPACE_DNS, name: str = 'zxwq') -> str:
    """基于SHA-1哈希的名称生成UUID 确定性"""
    return str(uuid.uuid5(namespace, name))


def uuid_fixed(length: int, prefix: str = None) -> str:
    """生成指定长度的带前缀的标识符"""
    uuid_str = uuid.uuid4().hex
    if prefix:
        uuid_str = f'{prefix}-{uuid_str[:length]}'
    else:
        uuid_str = uuid_str[:length]
    return uuid_str




if __name__ == "__main__":
    print("uuid_prefix:", uuid_prefix())
    print("uuid_hex:", uuid_hex())
    print("uuid_upper:", uuid_upper())
    print("uuid3_str:", uuid3_str())
    print("uuid5_str:", uuid5_str())
    print("uuid_fixed:", uuid_fixed(16))
